<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta content="telephone=no" name="format-detection" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta name="renderer" content="webkit" />
	<!--360自动切换极速-->
	<meta name="apple-mobile-web-app-title" content="DAN潜水" />
	<meta name="format-detection" content="telephone=no" />
	<link rel="shortcut icon" href="${ctxPath}/image/favicon.ico"/>
	<!--阻止iphone识别为电话-->
	<link rel="stylesheet" type="text/css" href="${ctxPath}/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="${ctxPath}/css/swiper.min.css" />
	<link rel="stylesheet" type="text/css" href="${ctxPath}/css/global.css" />
	<link rel="stylesheet" type="text/css" href="${ctxPath}/css/index.css" />
	<link rel="stylesheet" type="text/css" href="${ctxPath}/libs/datepicker/css/bootstrap-datepicker3.min.css" />
	<style>
		.dan-blank{
			text-align: center;
		}
		.dan-blank img{
			width: 120px;
			height: 120px;
		}
		.dan-blank div{
			font-size: 14px;
			margin-top: 30px;
		}
		.payed{
			text-align: center;
			position: relative;
			top: 60px;
		}
		.payed button{
			width: 200px;
			height: 40px;
			background: #D0001A;
			border-radius: 4px;
			font-size: 14px;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
		}
		.file-upload{
			display: inline-block;
			position: relative;
		}
		.file-upload input{
			width: 100%;
			height: 100%;
			position: absolute;
			left:0;
			top: 0;
			background:yellow;
			opacity: 0;
		}
		.delpic{
			position: absolute;
			right: 20px;
			top: 5px;
		}
	</style>
	<title>DAN潜水</title>
</head>

<body>
	<div class="container">
		@include("/include/header_zh_TW.html"){}
		<div class="user-info">
			<div class="row">
				<div class="col-lg-4">
					<h5 class="tit">會員資格</h5>
					<div class="card-bg">
						@if(user.memberLevel==1){
						<h6 class="sm-tit">會員資格</h6>
						<div class="item">
							<span class="label">會員資格:</span>
							--
						</div>
						<div class="item">
							<span class="label">開始時間:</span>
							--
						</div>
						<div class="item">
							<span class="label">有效期至:</span>
							--
						</div>
						<div class="item">
							<span class="label">狀態:</span>
							未開通
						</div>
						@}else{
						<h6 class="sm-tit">會員資格</h6>
						<div class="item">
							<span class="label">會員資格:</span>
							${user.memberNum!}
						</div>
						<div class="item">
							<span class="label">開始時間:</span>
							${user.memberBeginTime,dateFormat="yyyy年MM月dd日"}
						</div>
						<div class="item">
							<span class="label">有效期至:</span>
							${user.memberExpireTime,dateFormat="yyyy年MM月dd日"}
						</div>
						<div class="item">
							<span class="label">狀態:</span>
							${isNotEmpty(user.memberStatusDictData) ? user.memberStatusDictData.dictLabelZhtw! : ''}
						</div>
						@}
						<div class="btm">
							<a href="javascript:;" onclick="showPay()">開通/續費</a>
							<a href="javascript(void)" data-toggle="modal" data-target="#exchange">卡券兌換</a>
						</div>

					</div>
				</div>
				<div class="col-lg-8 order">
					<h5 class="tit">會員訂單</h5>
					<div class="card-bg">
						<h6 class="sm-tit">會員訂單</h6>
						<div class="table-box">
							@ if(isEmpty(orderList!)){
							<div class="dan-blank">
								<img src="${ctxPath}/image/blank.png" alt="">
								<div>暫無數據</div>
							</div>
							@}else{
							<table class="table table-bordered">
								<thead>
									<tr>
										<th>訂單號</th>
										<th>訂單類型</th>
										<th>日期</th>
										<th>價格</th>
										<th>卡號</th>
									</tr>
								</thead>
								<tbody>
								@ for(order in orderList!){
									<tr>
										<td><a href="${ctxPath}/order/info/${order.id!}">${order.orderSn!'/'}</a></td>
										<td>
											${isNotEmpty(order.orderTypeDictData) ? order.orderTypeDictData.dictLabelZhtw!'/' : '/'}
											@ if(order.orderType! == 1){
											@	if(order.payType! == 1){
											(微信)
											@   } else if(order.payType! == 2){
											(支付寶)
											@   }
											@ }
										</td>
										<td>${order.createTime!'/',dateFormat="yyyy-MM-dd"}</td>
										<td>${order.totalAmount!0}</td>
										<td>${order.cardNum!'/'}</td>
									</tr>
								@}
								</tbody>
							</table>
							@}
						</div>
						
					</div>
				</div>
			</div>
			<div class="member">
				<h5 class="tit">會員資訊</h5>
				<div class="card-bg row">
					<div class="item col-md-6">
						<span class="label">用戶名稱:</span>
						${user.nickname!}
					</div>
					<div class="item col-md-6">
						<span class="label">地址1:</span>
						${user.address1!}
					</div>
					<div class="item col-md-6">
						<span class="label">出生日期:</span>
						${user.birthday!,dateFormat="yyyy-MM-dd"}
					</div>
					<div class="item col-md-6">
						<span class="label">地址2:</span>
						${user.address2!}
					</div>
					<div class="item col-md-6">
						<span class="label">電子郵件:</span>
						${user.email!}
					</div>
					<div class="item col-md-6">
						<span class="label">國家:</span>
						${isNotEmpty(user.countryRegion) ? user.countryRegion.nameZhtw! : ''}
					</div>
					<div class="item col-md-6">
						<span class="label">手機1:</span>
						${user.mobile1!}
					</div>
					<div class="item col-md-6">
						<span class="label">郵遞區號:</span>
						${user.postcode!}
					</div>
					<div class="item col-md-6">
						<span class="label">手機2:</span>
						${user.mobile2!}
					</div>
					<div class="item col-md-6">
						<span class="label">所屬行業:</span>
						${user.industry.nameZhtw!}
					</div>
					<div class="item col-md-6">
						<span class="label">會員等級:</span>
						${isNotEmpty(user.memberLevelDictData) ? user.memberLevelDictData.dictLabelZhtw! : ''}
					</div>
					<div class="item col-md-6">
						<span class="label">潜水等級:</span>
						${isNotEmpty(user.diveLevelDictData) ? user.diveLevelDictData.dictLabelZhtw! : ''}
					</div>
					<div class="item col-md-6 mb-20">
						<span class="label">潜水體系:</span>
						${isNotEmpty(user.diveSystemDictData) ? user.diveSystemDictData.dictLabelZhtw! : ''}
					</div>
					<div class="item col-12 mb-20">
						<span class="label">證書照片:
							<p style="font-size:12px;color: #999;">大小限10M</p>
						</span>
						@for(img in memberImgList!){
							@if(img.type == 1){
							<img src="${img.imgUrl!}" alt="" class="pic">
							@}
						@}
					</div>
					<div class="item col-12 mb-20">
						<span class="label">會員照片:
							<p style="font-size:12px;color: #999;">大小限10M</p>
						</span>
						@for(img in memberImgList!){
						@if(img.type == 2){
						<img src="${img.imgUrl!}" alt="" class="pic">
						@}
						@}
					</div>
					<div class="edit col-12">
						<button class="btn btn-danger" data-toggle="modal" data-target="#user">修改</button>
					</div>
				</div>
			</div>
		</div>
		@include("/include/footer_zh_TW.html"){}
	</div>
	<!-- Modal/user-->
	<div class="modal fade dan-modal" id="user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">個人資訊編輯</h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
							aria-hidden="true">&times;</span></button>
				</div>
				<div class="modal-body">
					<form id="userEditForm" action="" class="form">
						<input type="hidden" name="id" value="${user.id!}"/>
						<div class="form-group row">
							<label class="col-3 control-label">用戶名稱：</label>
							<div class="col-9">
								<input id="nicknameInput" type="text" class="form-control" placeholder="請輸入用戶名稱" name="nickname" value="${user.nickname!}">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">出生日期：</label>
							<div class="col-9">
								<input type="text" class="dan-datepicker datepicker form-control"
									   data-date-format="yyyy-mm-dd"
									   placeholder="請選擇出生日期"
									   name="birthday" value='${user.birthday!,dateFormat="yyyy-MM-dd"}' id="birthdayInput">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">電子郵件：</label>
							<div class="col-9">
								<input id="emailInput" type="text" class="form-control" placeholder="請輸入電子郵件" name="email" value="${user.email!}">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">手機1：</label>
							<div class="col-9">
								<input id="mobile1Input" type="text" class="form-control" placeholder="請輸入手機1" name="mobile1" value="${user.mobile1!}" maxlength="11" disabled>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">手機2：</label>
							<div class="col-9">
								<input id="mobile2Input" type="text" class="form-control" placeholder="請輸入手機2" name="mobile2" value="${user.mobile2!}" maxlength="11">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">地址1：</label>
							<div class="col-9">
								<input id="address1Input" type="text" class="form-control" placeholder="請輸入地址1" name="address1" value="${user.address1!}">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">地址2：</label>
							<div class="col-9">
								<input id="address2Input" type="text" class="form-control" placeholder="請輸入地址2" name="address2" value="${user.address2!}">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">國家：</label>
							<div class="col-9">
								<select id="countrySelect" name="countryId" class="form-control" >
									<option value="">請選擇</option>
									@for(country in countryList!){
									<option value="${country.id!}" ${user.countryId! == country.id! ? "selected"} >${country.nameZhtw!}</option>
									@}
								</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">郵遞區號：</label>
							<div class="col-9">
								<input id="postcodeInput" type="text" class="form-control" placeholder="請輸入郵遞區號" name="postcode" value="${user.postcode!}">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">所屬行業：</label>
							<div class="col-9">
								<select id="industrySelect" name="industryId" class="form-control" >
									<option value="">請選擇</option>
									@for(industry in industryList!){
									<option value="${industry.id!}" ${industry.id! == user.industryId! ? 'selected' : ''}>${industry.nameZhtw!}</option>
									@}
								</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">潜水等級：</label>
							<div class="col-9">
								<select id="diveLevelSelect" name="diveLevel" class="form-control" >
									<option value="">請選擇</option>
									@for(diveLevel in diveLevelList!){
									<option value="${diveLevel.dictValue!}" ${parseInt(diveLevel.dictValue!'0') == user.diveLevel! ? 'selected' : ''}>${diveLevel.dictLabelZhtw!}</option>
									@}
								</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">潜水體系：</label>
							<div class="col-9">
								<select id="diveSystemSelect" name="diveSystem" class="form-control" >
									<option value="">請選擇</option>
									@for(diveSystem in diveSystemList!){
									<option value="${diveSystem.dictValue!}" ${parseInt(diveSystem.dictValue!'0') == user.diveSystem! ? 'selected' : ''}>${diveSystem.dictLabelZhtw!}</option>
									@}
								</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">證書照片：</label>
                            <div class="col-9" id="certificate-photo">
                                <div class="file-upload">
                                    <input type="file" accept="image/*"  id="certFile" value=""/>
                                    <img src="${ctxPath}/image/addpic.png" alt="" class="pic">
                                </div>
								@for(img in memberImgList!){
								@if(img.type == 1){
								<div class="file-upload">
									<input type="hidden" name="certImages" value="${img.imgUrl!}"/>
									<img src="${img.imgUrl!}" alt="" class="pic">
									<img src="${ctxPath}/image/ic_delpic.png" class="delpic" index="${imgLP.dataIndex!}" onclick="deletePic(this,'certificate-photo')"/>
								</div>
								@}
								@}
                            </div>
						</div>
						<div class="form-group row">
							<label class="col-3 control-label">會員照片：</label>
                            <div class="col-9" id="member-photo">
                                <div class="file-upload">
                                    <input type="file" accept="image/*"  id="memFile" value=""/>
                                    <img src="${ctxPath}/image/addpic.png" alt="" class="pic">
                                </div>
								@for(img in memberImgList!){
								@if(img.type == 2){
								<div class="file-upload">
									<input type="hidden" name="memImages" value="${img.imgUrl!}"/>
									<img src="${img.imgUrl!}" alt="" class="pic">
									<img src="${ctxPath}/image/ic_delpic.png" class="delpic" index="${imgLP.dataIndex!}" onclick="deletePic(this,'member-photo')"/>
								</div>
								@}
								@}
                            </div>
						</div>
					</form>
					<div class="submit">
						<button type="button" class="btn btn-danger dan-btn-full" onclick="subUserEditForm()">提交保存</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- Modal/pay-->
	<div class="modal fade dan-modal" id="pay" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">會員續費</h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
							aria-hidden="true">&times;</span></button>
				</div>
				<div class="modal-body">
					<div class="pay-tit">
						會員編號：${user.memberNum!}
					</div>
					<p class="content">
						有效期至：${user.memberExpireTime,dateFormat="yyyy年MM月dd日"}
					</p>
					<div class="pay-tit">
						購買套餐
					</div>
					<div class="prod-list">
						@if(isEmpty(rechargePackageList!)){
						暫無套餐
						@}else{
							@for(rechargePackage in rechargePackageList!){
							<div class="item pay-item ${rechargePackageLP.dataIndex == 0 ? 'active' : ''}" onclick="selectProd(this, '${rechargePackage.price!0}',${rechargePackage.id})">
								<div style="color:black;font-size:15px;margin-top:12px">${rechargePackage.nameZhtw!'-'}</div>
								<div class="price" style="margin:0"> <span>¥</span>${rechargePackage.price!0}</div>
								有效期：${rechargePackage.effectiveNum!0} ${rechargePackage.effectiveUnitDict.dictLabelZhtw!}
							</div>
							@}
						@}
					</div>
					<div class="pay-tit mb-20">
						金額：<div class="price inline">
								<span id="priceSpan">¥0</span>
								<input type="hidden" id="rechargePacageId"/>
							</div>
					</div>
					<div class="pay-tit mb-20">
						選擇支付方式
					</div>
					<div class="way">
						<input type="hidden" id="payWayInput" value="wx"/>
						<div class="way-item active" onclick="selectWay(this,'wx')">
							<object data="${ctxPath}/image/ic_wechat.svg" type="image/svg+xml"></object>
							微信支付
						</div>
						<div class="way-item" onclick="selectWay(this,'ali')">
							<object data="${ctxPath}/image/ic_alipay.svg" type="image/svg+xml"></object>
							支付寶
						</div>
						<div class="qr-code" id="qr-code-div">
							<img src="${ctxPath}/image/white.png" alt="">
						</div>
					</div>
					<div class="payed" id="button_div">
						<button class="btn" onclick="paySuccess()">支付完成</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- Modal/exchange-->
	<div class="modal fade dan-modal" id="exchange" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="myModalLabel">卡券兌換</h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
							aria-hidden="true">&times;</span></button>
				</div>
				<div class="modal-body" style="text-align:center">
					<input id="cardNumInput" type="text" class="exchange-input" placeholder="請輸入卡券編號">
					<button class="btn btn-danger exchange-btn" onclick="exchange();">兌換</button>
				</div>
			</div>
		</div>
	</div>
	<script src="${ctxPath}/js/swiper.min.js"></script>
	<script src="${ctxPath}/libs/datepicker/js/bootstrap-datepicker.min.js"></script>
	<script src="${ctxPath}/libs/datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
	<script>
		$('#birthdayInput').datepicker({
			autoclose:true,
			clearBtn:true,
			language: "zh-CN",
			startView: 0,
			format: "yyyy-mm-dd",
			date:  new Date()
		}).on('changeDate',function(ev){
			console.log('changeDate',ev)
		});
		var selectProd=function(that, price, packageId){
			var list=$('.pay-item')
			for(var i =0;i<list.length;i++){
				list.eq(i).removeClass('active')
			}
			$(that).eq(0).addClass('active')
			$("#priceSpan").html('￥'+price);
			var oldRechargePacageId = $("#rechargePacageId").val();
			$("#rechargePacageId").val(packageId);
			var payWay = $("#payWayInput").val();
			if(oldRechargePacageId != packageId && payWay != ''){
				subPay();
			}
		}
		var selectWay=function(that, payWay){
			var list=$('.way-item')
			for(var i =0;i<list.length;i++){
				list.eq(i).removeClass('active')
			}
			$(that).eq(0).addClass('active')
			var oldPayWay = $("#payWayInput").val();
			$("#payWayInput").val(payWay);
			var rechargePacageId = $("#rechargePacageId").val();
			if(oldPayWay != payWay && rechargePacageId != ''){
				subPay();
			}
		}

		@if(!isEmpty(rechargePackageList!)){
			$("#priceSpan").html('￥${rechargePackageList[0].price!0}');
			$("#rechargePacageId").val(${rechargePackageList[0].id});
			$("#payWayInput").val('wx');
		@}

		var showPay = function(){
			$('#pay').modal('show');
			subPay();
		}

        var certPhotoArr=[];
		var memberPhotoArr=[];
		@for(img in memberImgList!){
		@if(img.type == 1){
			certPhotoArr.push('${img.imgUrl!}');
		@}
		@if(img.type == 2){
			memberPhotoArr.push('${img.imgUrl!}');
		@}
		@}
		function showScanCode(payWay, imgData) {
			var qrDesc = payWay=='wx' ? '請用微信掃碼支付' : '請用支付寶掃碼支付';
			var html = '<img id="qr-code-img" src="data:image/gif;base64,'+imgData+'" alt="">\n' +
					'<div id="qr-desc">'+qrDesc+'</div>';
			$("#qr-code-div").html(html);
		}
		var paySuccess = function(){
			window.location.href='${ctxPath}/user/detail';
		}
		var subPay = function(){
			var packageId = $("#rechargePacageId").val();
			var payWay = $("#payWayInput").val();
			if(packageId == ''){
				alert('請選擇您要購買的套餐！');
				return false;
			}
			if(payWay == 'wx'){
				$.ajax({
					type: "post",
					dataType: "json",
					url: '${ctxPath}/api/v1/wxPay/scanCode2',
					data: {
						packageId:packageId
					},
					success: function(result){
						if(result.code == 500){
							alert("網絡异常，請稍後再試！");
						}else if(result.code != 200){
							alert(result.msg);
						}else{
							showScanCode('wx', result.img);
						}
					},
					error: function(){
						alert("網絡异常，請稍後再試！");
					}
				});
			}else if(payWay == 'ali'){
				$.ajax({
					type: "post",
					dataType: "json",
					url: '${ctxPath}/api/v1/aliPay/tradePreCreatePay',
					data: {
						packageId:packageId
					},
					success: function(result){
						if(result.code == 500){
							alert("網絡异常，請稍後再試！");
						}else if(result.code != 200){
							alert(result.msg);
						}else{
							showScanCode('ali', result.img);
						}
					},
					error: function(){
						alert("網絡异常，請稍後再試！");
					}
				});
			}else{
				alert('請選擇您使用的支付方式！');
				return false;
			}

		}

        var addImg=function(imgUrl,idName){
		    var inputName = idName == 'member-photo' ? 'memImages' : 'certImages';
		    var index = idName == 'member-photo' ? memberPhotoArr.length : certPhotoArr.length;
            // html=''
            // imgArr.forEach(function(item,index){
                html ='<div class="file-upload">' +
						'<input type="hidden" name="'+inputName+'" value="'+imgUrl+'"/>' +
						'<img src="'+imgUrl+'" alt="" class="pic">' +
						'<img src="${ctxPath}/image/ic_delpic.png" class="delpic" index='+index+' onclick="deletePic(this)"/>' +
						'</div>';
            // })
            $('#'+idName).append(html)
        }

        var deletePic=function(that, idName){
            var index=$(that).eq(0).attr('index')
			if(idName == 'member-photo'){
				memberPhotoArr.splice(index,1);
			}else{
				certPhotoArr.splice(index,1);
			}
            $(that).eq(0).parents('.file-upload').eq(0).remove()
        }

        // addImg(photoArr,'certificate-photo')
        // addImg(memberPhoto,'member-photo')

		// 图片上传
		oMemFile = document.querySelector("#memFile"); //获取input file节点
		oCertFile = document.querySelector("#certFile");
		oMemFile.addEventListener('change',function(){
			var file = this.files[0];
			if(file.type.indexOf("image")!=0){
				alert('只能上傳圖片');
				return false;
			}
			if(file.size > 10*1024*1024){
				alert('上傳圖片大小不能超過10M');
				return false;
			}
			var formData = new FormData();
			formData.append("file", file);
			formData.append("fileSavePath", "/member/member");
			$.ajax({
				type: "post",
				dataType: "json",
				url: '${ctxPath}/common/upload',
				data: formData,
				processData: false,
				contentType: false,   // jQuery不要去设置Content-Type请求头
				success: function (result) {
					if (result.code == 500) {
						alert("網絡异常，請稍後再試！");
					} else if (result.code != 200) {
						alert(result.msg);
					} else {
						addImg(result.url, 'member-photo');
					}
				},
				error: function () {
					alert("網絡异常，請稍後再試！");
				}
			});
		})
		oCertFile.addEventListener('change',function(){
			var file = this.files[0];
			if(file.type.indexOf("image")!=0){
				alert('只能上傳圖片');
				return false;
			}
			if(file.size > 10*1024*1024){
				alert('上傳圖片大小不能超過10M');
				return false;
			}
			var formData = new FormData();
			formData.append("file" ,file);
			formData.append("fileSavePath","/member/certificate");
			$.ajax({
				type: "post",
				dataType: "json",
				url: '${ctxPath}/common/upload',
				data: formData,
				processData: false,
				contentType: false,   // jQuery不要去设置Content-Type请求头
				success: function(result){
					if(result.code == 500){
						alert("網絡异常，請稍後再試！");
					}else if(result.code != 200){
						alert(result.msg);
					}else{
						addImg(result.url, 'certificate-photo');
					}
				},
				error: function(){
					alert("網絡异常，請稍後再試！");
				}
			});
		})
        exchange = function(){
            var cardNum = $("#cardNumInput").val();
            if(cardNum == ''){
                alert("請輸入兌換的卡券號碼");
                return false;
            }
            $.ajax({
                type: "post",
                dataType: "json",
                url: '${ctxPath}/user/exchange',
                data: {
                    cardNum: cardNum
                },
                success: function(result){
                    if(result.code == 500){
                        alert("網絡异常，請稍後再試！");
                    }else if(result.code != 200){
                        alert(result.msg);
                    }else{
                        alert("兌換成功");
                        window.location.reload();
                    }
                },
                error: function(){
                    alert("網絡异常，請稍後再試！");
                }
            });
        }

		function subUserEditForm(){

			var mobile2 = $("#mobile2Input").val();
			var email = $("#emailInput").val();
			if(mobile2 != '' && !checkPhone(mobile2)){
				alert("請輸入正確的手機號碼");
				return false;
			}
			if(email != '' && !checkEmail(email)){
				alert("請輸入正確的郵箱");
				return false;
			}

			$.ajax({
				type: "post",
				dataType: "json",
				url: '${ctxPath}/user/edit',
				data: $('#userEditForm').serialize(),
				success: function(result){
					if(result.code == 500){
						alert("網絡异常，請稍後再試！");
					}else if(result.code != 200){
						alert(result.msg);
					}else{
						alert("修改成功");
						window.location.reload();
					}
				},
				error: function(){
					alert("網絡异常，請稍後再試！");
				}
			});
		}

		function checkPhone(phone){
			return /^1[3456789]\d{9}$/.test(phone);
		}
		checkEmail = function(email){
			var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			return reg.test(email);
		}
	</script>
</body>

</html>